#ifndef HD_UTIL_H
#define HD_UTIL_H

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <errno.h>

#ifdef DEBUG_MODE
#define debug(format, ...) fprintf(stderr,"\033[31m[" __FILE__ " @ %d]: " format "\033[0m\n",__LINE__, ##__VA_ARGS__)
#else
#define debug(format, ...)
#endif

#define NULL_CHECK(expr, output)   if((expr)==NULL) exit_with_error(output)

#define FLAG_(num) (1 << (num - 1))
#define set_flag(x,fg) ((x) = (x)|(fg))
#define unset_flag(x,fg) ((x) = (x)&(~(fg)))
#define clear_flags(x) ((x) = 0)
#define is_flag_set(x,fg) (((x)&(fg)) == (fg))
#define is_flag_unset(x,fg) (!is_flag_set(x,fg))


void *emalloc(size_t size);
void efree(void *ptr);
void exit_with_error(const char * out);

#endif /* HD_UTIL_H */
